﻿namespace MicroCloud.Events
{
    /// <summary>
    /// 实体事件数据
    /// </summary>
    /// <typeparam name="TEntity">实体对象类型</typeparam>
    public class EntityEventData<TEntity> : EventDataBase
        where TEntity : IEntityBase
    {
        /// <summary>
        /// 初始化一个实体事件数据 <see cref="EntityEventData{TEntity}"/> 的新实例
        /// </summary>
        /// 
        /// <param name="dbContext">数据上下文</param>
        /// <param name="operateType">实体操作类型</param>
        public EntityEventData(IDbContext dbContext, OperateType operateType)
        {
            Check.NotNull(dbContext, nameof(dbContext));
            Check.NotNull(operateType, nameof(operateType));

            DbContext = dbContext;
            OperateType = operateType;
        }

        #region 属性
        /// <summary>
        /// 获取 数据上下文
        /// </summary>
        public IDbContext DbContext { get; }
        
        /// <summary>
        /// 获取 操作类型
        /// </summary>
        public OperateType OperateType { get; }
        
        /// <summary>
        /// 获取或设置 实体集合
        /// </summary>
        public List<TEntity> Entities { get; set; } = new();

        #endregion

        #region 方法
        /// <summary>
        /// 是否有值
        /// </summary>
        public bool HasData()
        {
            return Entities?.Count > 0;
        }

        #endregion

    }

}